
*****************************************************************************************************
************                     Replication Code (Version 1.0) For:                   **************
************ Political Alignment and the Allocation of Stock Market Resources in China **************
*****************************************************************************************************

*** This .do file reproduces: (a) Table 1,2, and 3 in the main text;
***                           (b) Figure 2 in the main text;
***                           (c) Table C2, C4(Panel B), Table D2 to Table D9 in the online appendix;
***                           (d) Figure D1 and D2 in the online appendix.

set matsize 11000
set more off
clear

use Firm_Application.dta
drop if mcprom==. 
gen suc_dummy = (success == 1) 

***************************
*** Data Pre-processing ***
***************************

** Create numeric dummies for province, city, industry, board, and sponsor
egen ind_code = group(industry_csrc)
egen pro_code = group(province)
egen city_code = group(city)
egen board_code = group(board)
egen sponsor_code = group(sponsor)

** Rescale and log transformation for pre-IPO firm characteristics
gen lgprofit=ln(profit0 + 1)
gen lgncf=ln(netcashflow0 + 1)
gen lgfs=ln(firmsize0 + 1)
gen tax=corporate_tax + business_tax
gen tax_ratio=tax/(rev0+1)*100
replace tax_ratio =. if tax_ratio > 100
gen subsidy_ratio = govtsubsidy0/(rev0+1)*100
replace subsidy_ratio =. if subsidy_ratio > 100
gen innov_ratio =innov_exp/(rev0+1)*100
replace netcashflow0 = netcashflow0/1000
replace registered_capital = registered_capital/1000
gen lgcapital = ln(registered_capital + 1)
gen lggovsub = ln(govtsubsidy0 + 1)
gen soe_dummy = (StateOwnedShares > 0 & StateOwnedShares !=.)
gen soe_control = (StateOwnedShares >= 0.5 & StateOwnedShares !=.)
sort id year0,stable
gen first_ipo = 0
replace first_ipo = 1 if id[_n] != id[_n-1]

** City characeristics
replace gdp=gdppc*pop if gdp==.
gen lggdp=ln(gdp + 1)
gen lggdppc=ln(gdppc + 1)
gen lgpop=ln(pop + 1)
gen linv = ln(investment + 1)
gen lgovrev = ln(govrev + 1)
gen lgovexp = ln(govexp + 1)
gen unerate = unemployment / (pop * 100)

** Data on Firm's direct political connections
gen symbol = substr(id,1,6)
gen yearend = year1
merge m:1 symbol yearend using Firm_Connection.dta
drop if _merge == 2
drop _merge
replace firm_pc = 0 if firm_pc ==.
replace pc_low = 0 if pc_low ==.
replace pc_city = 0 if pc_city ==.
gen pc_county = (pc_low == 1 & pc_city == 0)
gen firm_nlpc = (firm_pc == 1 & pc_county == 0)
replace npc = firm_nlpc

*********************
*** Data Analysis ***
*********************

***** Table 1 *****
sum suc_dummy mcprom mchome mccollege mcwork pcprom pchome pccollege pcwork
sum roa0 roe0 lgfs age alratio0 lgcapital StateOwnedShares npc lgncf tax_ratio subsidy_ratio innov_ratio duration_y
sum lgpop lggdp lggdppc gdpgrowth linv lgovrev lgovexp unerate

***** Table 2 *****
bysort mcprom: sum(roa0 roe0 firmsize0 age alratio registered_capital netcashflow0 ///
                   npc StateOwnedShares tax_ratio subsidy_ratio) 
eststo clear
eststo: qui reg roa0 mcprom, vce(cluster city_code)
eststo: qui reg roe0 mcprom, vce(cluster city_code)
eststo: qui reg firmsize0 mcprom, vce(cluster city_code)
eststo: qui reg age mcprom, vce(cluster city_code)
eststo: qui reg alratio0 mcprom, vce(cluster city_code)
eststo: qui reg registered_capital mcprom, vce(cluster city_code)
eststo: qui reg netcashflow0 mcprom, vce(cluster city_code)
eststo: qui reg npc mcprom, vce(cluster city_code)
eststo: qui reg StateOwnedShares mcprom, vce(cluster city_code)
eststo: qui reg tax_ratio mcprom, vce(cluster city_code)
eststo: qui reg subsidy_ratio mcprom, vce(cluster city_code)
esttab, p b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(mcprom) replace  // show p-value

***** Appendix Table C2 *****
global conn_var npc StateOwnedShares   // firm's direct connection
global firm_var roa0 roe0 lgfs age alratio0 lgcapital   // firm attributes
global city_var lgpop lggdp lggdppc gdpgrowth lgovrev lgovexp linv unerate   // city attributes

capture drop missing
gen missing = 1 - non_missing
eststo clear
eststo: qui reg missing mcprom, cluster(city_code)
eststo: qui reghdfe missing mcprom, a(city_code) cluster(city_code)
eststo: qui reghdfe missing mcprom duration_y, a(city_code board_code sponsor_code) cluster(city_code)
eststo: qui reghdfe missing mcprom duration_y, a(ind_code city_code board_code sponsor_code) cluster(city_code)
eststo: qui reghdfe missing mcprom duration_y $firm_var $conn_var, a(city_code board_code sponsor_code) cluster(city_code)
eststo: qui reghdfe missing mcprom duration_y $firm_var $conn_var $city_var, a(city_code board_code sponsor_code) cluster(city_code)
esttab, se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(mcprom) replace
estadd ysumm

***** Table 3 *****
eststo clear
eststo: qui reghdfe suc_dummy mcprom, a(i.year0 city_code) vce(cluster city_code)  // city FE and application year FE
eststo: qui reghdfe suc_dummy mcprom duration_y, a(city_code board_code i.year0##i.sponsor_code) vce(cluster city_code) // + application attributes (duration, board and underwriter)
eststo: qui reghdfe suc_dummy mcprom duration_y, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + industry FE
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + firm attributes 
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + city attributes
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(mcprom) replace
estadd ysumm

***** Figure 2 *****
capture drop z2*
foreach x of var roa0 roe0 lgfs age alratio0 StateOwnedShares {
	egen z2`x' = std(`x') 
}
label var mcprom "Political Alignment"
label var z2roa0 "ROA"
label var z2roe0 "ROE"
label var z2lgfs "Firm size"
label var z2age "Firm age"
label var z2alratio0 "Asset-liability ratio"
label var z2StateOwnedShares "State-owned shares"
label var npc "PC/CPPCC"

reghdfe suc_dummy mcprom duration_y z2roa0 z2roe0 z2lgfs z2age z2alratio0 z2StateOwnedShares npc $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // coefficients
coefplot, keep(mcprom z2* npc) xline(0) mfcolor(white) level(95) pstyle(p3) scheme(s1color)  // plot

***** Appendix Table D3 and Figure D2 *****
teffects psmatch (suc_dummy) (mcprom lgcapital lgncf city_code year0)
teffects psmatch (suc_dummy) (mcprom lgcapital lgncf city_code board_code c.year0##c.sponsor_code)
teffects psmatch (suc_dummy) (mcprom lgcapital lgncf $conn_var city_code board_code c.year0##c.sponsor_code)
teffects psmatch (suc_dummy) (mcprom lgcapital lgncf $firm_var $conn_var ind_code city_code board_code c.year0##c.sponsor_code)
teffects psmatch (suc_dummy) (mcprom lgcapital lgncf $firm_var $conn_var $city_var ind_code city_code board_code c.year0##c.sponsor_code)
teffects psmatch (suc_dummy) (mcprom lgcapital lgncf $firm_var $conn_var $city_var ind_code c.year1##c.pro_code city_code board_code c.year0##c.sponsor_code)
estadd ysumm
tebalance box // plot

***** Appendix Table D2 *****
global firm_var2 lgfs age alratio0 lgcapital
gen state_ctrl = (StateOwnedShares >= 0.5) if StateOwnedShares !=.
eststo clear
eststo: qui reghdfe suc_dummy mcprom##i.npc duration_y $firm_var2 $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
eststo: qui reghdfe suc_dummy mcprom##i.state_ctrl duration_y $firm_var2 $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
eststo: qui reghdfe suc_dummy mcprom##c.roa duration_y $firm_var2 $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
eststo: qui reghdfe suc_dummy mcprom##c.roe duration_y $firm_var2 $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(1.mcprom*) replace

***** Appendix Figure D1 *****
gen year_sponsor = year0*10000+sponsor_code
interflex suc_dummy mcprom roa duration_y $firm_var2 $city_var, fe(city_code board_code ind_code year_sponsor) cluster (city_code) type(binning)
interflex suc_dummy mcprom roe duration_y $firm_var2 $city_var, fe(city_code board_code ind_code year_sponsor) cluster (city_code) type(binning)

***** Appendix Table D4 *****
eststo clear
eststo: qui reghdfe suc_dummy mchome, a(i.year0 city_code) vce(cluster city_code)  // city FE and application year FE
eststo: qui reghdfe suc_dummy mchome duration_y $firm_var $conn_var $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
eststo: qui reghdfe suc_dummy mcwork, a(i.year0 city_code) vce(cluster city_code)  // city FE and application year FE
eststo: qui reghdfe suc_dummy mcwork duration_y $firm_var $conn_var $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
eststo: qui reghdfe suc_dummy mccollege, a(i.year0 city_code) vce(cluster city_code)  // city FE and application year FE
eststo: qui reghdfe suc_dummy mccollege duration_y $firm_var $conn_var $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(mchome mcwork mccollege) replace
estadd ysumm

***** Appendix Table D5 *****
eststo clear
eststo: qui reghdfe suc_dummy pcprom, a(i.year0 city_code) vce(cluster city_code)  // city FE and application year FE
eststo: qui reghdfe suc_dummy pcprom duration_y, a(city_code board_code i.year0##i.sponsor_code) vce(cluster city_code) // + application attributes (duration, board and underwriter)
eststo: qui reghdfe suc_dummy pcprom duration_y, a(ind_code city_code board_code i.year0##i.sponsor_code) vce(cluster city_code)  // + industry FE
eststo: qui reghdfe suc_dummy pcprom duration_y $firm_var $conn_var, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + firm attributes
eststo: qui reghdfe suc_dummy pcprom duration_y $firm_var $conn_var $city_var, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + city attributes
eststo: qui reghdfe suc_dummy pcprom duration_y $firm_var $conn_var $city_var, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(pcprom) replace
estadd ysumm

***** Appendix Table D6 *****
eststo clear
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var if board_code !=3, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var if ind_code !=17 & ind_code !=9, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var if first_ipo == 1, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var, a(i.IEC i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var innov_ratio, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var tax_ratio subsidy_ratio lgncf, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)
esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(mcprom) replace
 
***** Appendix Table D7 *****
eststo clear
eststo: qui reghdfe suc_dummy mcprom if non_missing, a(i.year0 city_code) vce(cluster city_code)  // city FE and application year FE
eststo: qui reghdfe suc_dummy mcprom duration_y if non_missing, a(city_code board_code i.year0##i.sponsor_code) vce(cluster city_code) // + application attributes (duration, board and underwriter)
eststo: qui reghdfe suc_dummy mcprom duration_y if non_missing, a(ind_code city_code board_code i.year0##i.sponsor_code) vce(cluster city_code)  // + industry FE
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var if non_missing, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + firm attributes
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var if non_missing, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + city attributes
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var if non_missing, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(mcprom) replace

***** Appendix Table D8 *****
eststo clear
eststo: qui reghdfe suc_dummy mcprom if year0>= 2013, a(i.year0 city_code) vce(cluster city_code)  // city FE and application year FE
eststo: qui reghdfe suc_dummy mcprom duration_y if year0>= 2013, a(city_code board_code i.year0##i.sponsor_code) vce(cluster city_code) // + application attributes (duration, board and underwriter)
eststo: qui reghdfe suc_dummy mcprom duration_y if year0>= 2013, a(ind_code city_code board_code i.year0##i.sponsor_code) vce(cluster city_code)  // + industry FE
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var if year0>= 2013, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + firm attributes
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var if year0>= 2013, a(city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + city attributes
eststo: qui reghdfe suc_dummy mcprom duration_y $firm_var $conn_var $city_var if year0>= 2013, a(i.pro_code##c.year0 city_code board_code ind_code i.year0##i.sponsor_code) vce(cluster city_code)  // + province-year trends
esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(mcprom) replace

***** Appendix Table D9 *****
eststo clear
eststo: qui reghdfe suc_dummy mcprom##i.ind_code, a(i.year0 city_code) vce(cluster city_code) 
eststo: qui reghdfe suc_dummy mcprom##i.ind_code duration_y $firm_var $conn_var, a(city_code board_code i.year0##i.sponsor_code) vce(cluster city_code)  
eststo: qui reghdfe suc_dummy mcprom##i.ind_code duration_y $firm_var $conn_var $city_var, a(city_code board_code i.year0##i.sponsor_code) vce(cluster city_code)  
eststo: qui reghdfe suc_dummy mcprom##i.ind_code duration_y $firm_var $conn_var $city_var, a(i.pro_code##c.year0 city_code board_code i.year0##i.sponsor_code) vce(cluster city_code)  
esttab, se b(3) t(3) scalars(N_clust) star(* 0.1 ** 0.05 *** 0.01) keep(1.mcprom*) replace


***** Appendix Table C4 (Panel B) *****
clear
use Private_Firm_Survey.dta  // 2006 Private Firm Survey

* Recode city-level control variables
replace gdp=gdppc*pop if gdp==.
gen lggdp=ln(gdp + 1)
gen lggdppc=ln(gdppc + 1)
gen lgpop=ln(pop + 1)
gen linv = log(investment + 1)
gen lgovrev = log(govrev + 1)
gen lgovexp = log(govexp + 1)
gen unerate = unemployment / (pop * 100)
egen pro_code = group(province)
egen city_code = group(city)

eststo clear
eststo: qui areg ipo1 faction, a(pro_code) vce(cluster city_code)
eststo: qui areg ipo1 faction lgprofit lgfs age npc1, a(pro_code) vce(cluster city_code)
eststo: qui areg ipo1 faction lgprofit lgfs age npc1 lgpop lggdp lggdppc gdpgrowth lgovrev lgovexp linv unerate, a(pro_code) vce(cluster city_code)
esttab, se b(3) t(3) star(* 0.1 ** 0.05 *** 0.01) keep(faction) replace
